import Cookies from 'js-cookie'

const TokenKey = 'Authorization_TOKEN'
const CorpKey = 'CORP_ID'

export function getToken() {
    let token = Cookies.get(TokenKey)
    let param = location.href.split('?')[1]
    if (param && param.length > 0) {
        var params = param.split('&')
        for (let index = 0; index < params.length; index++) {
            var key = params[index].split('=')[0]
            if (key == 'token') {
                token = params[index].split('=')[1]
                Cookies.set(TokenKey, token)
            }
        }
    }
    return token
}

export function setToken(token) {
    return Cookies.set(TokenKey, token)
}

export function removeToken() {
    return Cookies.remove(TokenKey)
}

export function setCorp(token) {
    return Cookies.set(CorpKey, token)
}

export function getCorp() {
    return Cookies.get(CorpKey)
}

export function removeCorp() {
    return Cookies.remove(CorpKey)
}